<%-- 
    Document   : chk
    Created on : May 17, 2014, 2:32:18 AM
    Author     : Yogesh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>


        <%


                       org.hibernate.SessionFactory sessionFactory=com.Auto.Common.Userinformtion.Hibernate.Userinformation_HibernateUtil.getSessionFactory();
                       org.hibernate.Session Opensession=sessionFactory.openSession();
                       org.hibernate.Transaction transaction=Opensession.beginTransaction();

                       String emailId=(String)request.getParameter("emailId");
                       String password=(String)request.getParameter("password");


                       out.print(emailId+" "+password);


                        org.hibernate.Query query=Opensession.createQuery("from com.Auto.Common.Userinformtion.Hibernate.Userinformation where emailId='"+emailId+"' and password='"+password+"'");


                         java.util.List l=query.list();



                       if(l.isEmpty()){
                            response.sendRedirect("LoginFails.jsp");
                       }
                    else{


                        String status="";
                    String pic="";

                   for(Object o:l){

                      com.Auto.Common.Userinformtion.Hibernate.Userinformation uifor=(com.Auto.Common.Userinformtion.Hibernate.Userinformation)o;



                                            String id1=uifor.getId()+"";
                                            status=uifor.getProfileState();

                                        session.setAttribute("firstName", uifor.getFirstName());
                                        session.setAttribute("lastName",uifor.getLastName());
                                        session.setAttribute("id", id1);
                                        session.setAttribute("middelName", uifor.getMiddelName());
                                        session.setAttribute("address",uifor.getAddress());
                                        session.setAttribute("mobileNumber",uifor.getMobileNumber());
                                        session.setAttribute("emailId",uifor.getEmailId());
                                        session.setAttribute("gender",uifor.getGender());
                                        session.setAttribute("dob",uifor.getDob());
                                        session.setAttribute("password",uifor.getPassword());
                                        session.setAttribute("city",uifor.getCity());
                                        session.setAttribute("CountryState",uifor.getCountryState());
                                        session.setAttribute("pinCode",uifor.getPinCode());
                                        session.setAttribute("contry",uifor.getContry());
                                        session.setAttribute("profPic",uifor.getProfPic());
                                        session.setAttribute("activationCode",uifor.getActivationCode());
                                        session.setAttribute("profileState",uifor.getProfileState());
                                        session.setAttribute("profileStatus",uifor.getProfileStatus());
                                        session.setAttribute("profileCompletion",uifor.getProfileCompletion());

                                        String firstName=uifor.getFirstName();
                                        String lastName=uifor.getLastName();

                                        session.setAttribute("copyfirstName",firstName);
                                        session.setAttribute("copylastName",lastName);


                                        //----Image Retrival-----
                                        String profPic="";
                                        String path=uifor.getProfPic();
                                        
                                        java.io.BufferedReader br = null;

                                        try {

                                        String sCurrentLine;

                                        br = new java.io.BufferedReader(new java.io.FileReader(""+path+""));

                                        while ((sCurrentLine = br.readLine()) != null) {
                                                profPic=profPic+sCurrentLine;
                                        }

                                        } catch (Exception e) {
                                                e.printStackTrace();
                                        }



                                        session.setAttribute("profPic",path);
                                        
                                        //----Image Retrival-----






                       }

                                     String flag="1";


                                     String  message=(String)session.getAttribute("message");
                                     String pageRedir=(String)session.getAttribute("pageRedir");
                                    

                                if(message==null){
                                    }else{

                                         
                                         flag="0";                                      
                                    }


                                        if(flag.equals("1")){

                                                       if(status.equals("0")){

                                                        response.sendRedirect("NotActivated.jsp");

                                                        }
                                                      else{

                                                                 response.sendRedirect("profile.jsp");

                                                            }
                                            }
                                     else{
                                                  if(message.equals("tender")){
                                            session.setAttribute("message",null);
                                                response.sendRedirect("orderTender.jsp");
                                        }


                                        if(message.equals("insurence")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("insuranceregi.jsp");
                                            }

                                         if(message.equals("MyInsurance")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("MyInsurance.jsp");
                                            }

                                          if(message.equals("MyPostedAd")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("MyPostedAd.jsp");
                                            }

                                          if(message.equals("profile")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("profile.jsp");
                                            }

                                          if(message.equals("ProfileCompletion")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("ProfileCompletion.jsp");
                                            }

                                          if(message.equals("postAd")){

                                                    session.setAttribute("message",null);
                                                response.sendRedirect("postAd.jsp");
                                            }




                                         }

                                                 
                        }
                         
                            



        %>
    </body>
</html>
